import { Service } from '../core';
class AccountService extends Service {
	constructor() {
		super(...arguments);
		this.login = account =>
			this.request({
				method: this.method.POST,
				url: '/login',
				data: account
			});
		this.logout = () =>
			this.request({
				method: this.method.DELETE,
				url: '/logout'
			});
		this.information = () =>
			this.request({
				method: this.method.GET,
				url: '/information'
			});
		this.upgradeInfo = () =>
			this.request({
				method: this.method.PUT,
				url: '/authorization'
			});
		this.upgradePassword = (oldPassword, newPassword) =>
			this.request({
				method: this.method.PUT,
				url: '/password',
				data: {
					oldPassword,
					newPassword
				}
			});
		this.upgradePhone = (password, newPhone) =>
			this.request({
				method: this.method.PUT,
				url: '/phone',
				data: {
					password,
					newPhone
				}
			});
		this.deletePhone = () =>
			this.request({
				method: this.method.DELETE,
				url: '/phone'
			});
		this.upgradeEmail = (password, newEmail) =>
			this.request({
				method: this.method.PUT,
				url: '/email',
				data: {
					password,
					newEmail
				}
			});
		this.deleteEmail = () =>
			this.request({
				method: this.method.DELETE,
				url: '/email'
			});
		this.upgradeAvatar = avatar => {
			const formData = new FormData();
			formData.append('avatar', avatar);
			return this.request({
				headers: {
					'Content-Type': 'multipart/form-data'
				},
				method: this.method.PUT,
				url: '/avatar',
				data: formData
			});
		};
	}
	create() {
		return this.initTokenInstance('account');
	}
}
export const accountService = new AccountService();
